import request from '@neu/biz-core/utils/request'
const baseUrl = '/dcam/api/w/fixedAsset'

export const list = () => {
  return request({
    url: baseUrl,
    method: 'get'
  })
}

export const page = (params) => {
  return request({
    url: baseUrl + '/p',
    params,
    method: 'get'
  })
}

export const create = (data) => {
  return request({
    url: baseUrl,
    data,
    method: 'post'
  })
}

export const remove = (id) => {
  return request({
    url: baseUrl + '/' + id,
    method: 'delete'
  })
}

export const batchRemove = (ids) => {
  return request({
    url: baseUrl + '/batch/' + ids,
    method: 'delete'
  })
}

export const scrap = (ids) => {
  return request({
    url: baseUrl + '/batchHandles/' + ids,
    method: 'delete'
  })
}

export const qrcode = (ids) => {
  return request({
    url: baseUrl + '/qrcode/' + ids,
    method: 'get',
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/pdf'
    }
  })
}

export const insititutions = () => {
  return request({
    url: baseUrl + '/insititutions',
    method: 'get'
  })
}

export const detail = (id) => {
  return request({
    url: baseUrl + '/' + id,
    method: 'get'
  })
}

export const update = (id, data) => {
  return request({
    url: baseUrl + '/' + id,
    data,
    method: 'put'
  })
}

export const exportExcel = (params) => {
  return request({
    url: baseUrl + '/export',
    params,
    method: 'get',
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/octet-stream'
    }
  })
}

export const importExcelUrl = baseUrl + '/import'

export const template = (params) => {
  return request({
    url: baseUrl + '/template',
    params,
    timeout: 120000,
    method: 'get',
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/octet-stream'
    }
  })
}

export const getInstitutionsFromDcom = () => {
  return request({
    url: '/dcom/api/w/operationGroups',
    method: 'get'
  })
}

export const listInstitutions = (params) => {
  return request({
    url: 'dcom/api/w/institutions',
    params,
    method: 'get'
  })
}

export const valueReport = (params) => {
  return request({
    url: baseUrl + '/stats/report',
    params,
    method: 'get'
  })
}


export const exportValueReport = (params) => {
  return request({
    url: baseUrl + '/stats/export',
    params,
    method: 'get',
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/octet-stream'
    }
  })
}

export const maintenanceReport = (params) => {
  return request({
    url: baseUrl + '/stats/maintenance/report',
    params,
    method: 'get'
  })
}

export const exportMaintenanceReport = (params) => {
  return request({
    url: baseUrl + '/stats/maintenance/export',
    params,
    method: 'get',
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/octet-stream'
    }
  })
}

export const lifeCycle = (ids, status) => {
  return request({
    url: baseUrl + '/batchHandles/' + ids + '/' + status,
    method: 'put'
  })
}

export const getAttachment = (assetId) => {
  return request({
    url: baseUrl + '/attach/' + assetId,
    method: 'get'
  })
}

export const attach = (data) => {
  return request({
    url: baseUrl + '/attach',
    method: 'put',
    data
  })
}

export const uploadFileUrl = '/dcam/api/w/files/upload'

export const downloadFileUrl = (fsId) => {
  return '/dcam/api/w/files/download/' + fsId
}

export const lifeCyclePage = (code) => {
  return () => {
    return request({
      url: baseUrl + '/lifecycle/p',
      params: {
        s_code: code
      },
      method: 'get'
    })
  }
}

export const statsByType = () => {
  return request({
    url: baseUrl + '/statsByType',
    method: 'get'
  })
}

export const statsByInstitution = () => {
  return request({
    url: baseUrl + '/statsByInstitution',
    method: 'get'
  })
}

export const statsByStatus = () => {
  return request({
    url: baseUrl + '/statsByStatus',
    method: 'get'
  })
}
